//
//  BaseTableViewCell.m
//  GoldBook
//
//  Created by wmz on 2021/8/15.
//  Copyright © 2021 wmz. All rights reserved.
//

#import "BaseTableViewCell.h"

@implementation BaseTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    return [self cellWithTableView:tableView identifier:nil];
}

+ (instancetype)cellWithTableView:(UITableView *)tableView identifier:(NSString *_Nullable)identifier {
    if (!identifier) {
        identifier = NSStringFromClass(self);
    }
    BaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpConfig];
    }
    return self;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    [self setUpConfig];
}

- (void)setUpConfig{
    [self hd_setupViews];
    [self hd_bindViewModel];
    [self setNeedsUpdateConstraints];
}

- (void)hd_setupViews {
}

- (void)hd_bindViewModel {
}

- (void)setGNModel:(id)data{
    
}

- (UIView *)lineView{
    if (!_lineView) {
        _lineView = UIView.new;
        _lineView.backgroundColor = wColor_line;
        [self.contentView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(0);
            make.height.mas_equalTo(PostK1px);
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
        }];
    }
    return _lineView;
}

#pragma mark - HDSkeletonLayerLayoutProtocol
- (NSArray<HDSkeletonLayer *> *)skeletonLayoutViews {


    HDSkeletonLayer *circle = [[HDSkeletonLayer alloc] init];
    const CGFloat iconW = 60;
    [circle hd_makeFrameLayout:^(HDFrameLayoutMaker *_Nonnull make) {
        make.width.hd_equalTo(iconW);
        make.height.hd_equalTo(iconW);
        make.left.hd_equalTo(15);
        make.top.hd_equalTo(15);
    }];
    circle.skeletonCornerRadius = iconW * 0.5;

    HDSkeletonLayer *r2 = [[HDSkeletonLayer alloc] init];
    [r2 hd_makeFrameLayout:^(HDFrameLayoutMaker *_Nonnull make) {
        make.left.hd_equalTo(circle.hd_right).offset(10);
        make.width.hd_equalTo(PostWidth * 0.4);
        make.top.hd_equalTo(circle.hd_top).offset(3);
        make.height.hd_equalTo(15);
    }];

    HDSkeletonLayer *r3 = [[HDSkeletonLayer alloc] init];
    [r3 hd_makeFrameLayout:^(HDFrameLayoutMaker *_Nonnull make) {
        make.left.hd_equalTo(r2.hd_left);
        make.width.hd_equalTo(PostWidth * 0.3);
        make.top.hd_equalTo(r2.hd_bottom + 10);
        make.height.hd_equalTo(15);
    }];

    HDSkeletonLayer *r4 = [[HDSkeletonLayer alloc] init];
    [r4 hd_makeFrameLayout:^(HDFrameLayoutMaker *_Nonnull make) {
        make.left.hd_equalTo(15);
        make.width.hd_equalTo(PostWidth * 0.7);
        make.top.hd_equalTo(circle.hd_bottom).offset(15);
        make.height.hd_equalTo(26);
    }];
    r4.cornerRadius = 13;

    return @[circle, r2, r3, r4];
}

- (UIColor *)skeletonContainerViewBackgroundColor {
    return UIColor.whiteColor;
}

+ (CGFloat)skeletonViewHeight {
    return 130;
}

@end
